package tbkmaterial

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	// "os"
)

//物料列表结构
type MaterialList struct {
	MaterialIdList []MaterialItem `json:"materialIdList"`
}

func (m *MaterialList) AddItem(item MaterialItem) {
	oldList := m.MaterialIdList

	m.MaterialIdList = append(oldList, item)
}

func (m *MaterialList) WriteToFile(filePath string) {
	body, err := json.Marshal(m)
	if err != nil {
		fmt.Printf("json marshal err: %s", err)
		return
	}
	err = ioutil.WriteFile(filePath, body, 0666)
	if err != nil {
		fmt.Printf("ioutil.WriteFile err:%s", err)
	}
}
